<?php

namespace app\index\controller;

use Jenssegers\Agent\Agent;
use think\Controller;
use think\Db;
use think\Request;

class Game extends Controller
{
    public function cocos_game()
    {
        $agent = new Agent();
        if(!$agent->isMobile()){
            http_response_code(404);exit;
        }
        return $this->fetch('cocos/game');
    }

    public function project()
    {
        echo '{"showFPS": false, "noCache": false, "frameRate": 60, "project_type": "javascript", "debugMode": 1, "renderMode": 0, "id": "gameCanvas"}';
    }

    // 防止作弊
    public function logs(Request $request)
    {
        if($this->request->post('id', '')) {
            $data = [
                'type' => $request->param('type', ''),
                'count' => $request->param('count', ''),
                'order_id' => $request->param('id', ''),
                'created_at' => time()
            ];
            Db::name('StoreGameLog')->insert($data);
        }
    }
}
